{/* LAYOUT模板 */}
	<layout name="layout"/>
{/* LAYOUT模板 */}

{/* import Js,Css */}
	<js href="__PUBLIC__/js/admin/listTable.js"/>
	<js href="__PUBLIC__/js/admin/js.util.js"/>
	<css href="__PUBLIC__/css/admin/common.css"/>
	<js href="__PUBLIC__/js/admin/js.selectzone.js"/>
	
	<css href="__PUBLIC__/css/jquery-ui.css" />
	<js href="__PUBLIC__/js/core/jquery-ui.1.10.4.js" />
	<js href="__PUBLIC__/js/core/plugins.js"/>
{/* import js,css */}

<!-- [position] -->
	<include file="Template:position"/>
<!-- [position] -->

<div class="form-div">
	<form action="javascript:searchSnatch()" name="searchForm">
		<img src="__PUBLIC__/image/admin/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
		活动名称
		<input type="text" name="keyword" /> 
		<input type="submit" value="搜索"/>
	</form>
</div>

<form method="post" action="" name="listForm">
	<div class="list-div" id="listDiv">
		<table cellpadding="3" cellspacing="1" width="100%">
			<tr>
				<th><a href="javascript:listTable.sort('act_id'); ">编号</a>{$sort_act_id}</th>
				<th><a href="javascript:listTable.sort('snatch_name'); ">活动名称</a>{$sort_snatch_name}</th>
				<th><a href="javascript:listTable.sort('goods_name'); ">商品名称</a>{$sort_goods_name}</th>
				<th><a href="javascript:listTable.sort('start_time'); ">活动开始时间</a>{$sort_start_time}</th>
				<th><a href="javascript:listTable.sort('end_time'); ">活动结束时间</a>{$sort_end_time}</th>
				<th>价格下限</a></th>
				<th>消耗积分</a></th>
				<th>操作</th>
			</tr>
			<volist name="snatch_list" id="snatch">
			<tr>
				<td align="center">{$snatch.act_id}</td>
				<td class="first-cell">
					<span onclick="listTable.edit(this, 'edit_snatch_name', {$snatch.act_id})">{$snatch.snatch_name}</span>
				</td>
				<td><span>{$snatch.goods_name}</span></td>
				<td align="center">{$snatch.start_time}</td>
				<td align="center">{$snatch.end_time}</td>
				<td align="right">{$snatch.start_price}</td>
				<td align="right">{$snatch.cost_points}</td>
				<td align="center">
					<a href="__URL__/view_snatch?snatch_id={$snatch.act_id}" title="查看详情">
						<img src="__PUBLIC__/image/admin/icon_view.gif" border="0" height="16" width="16">
					</a>
					<a href="__URL__/mod_snatch?id={$snatch.act_id}" title="修改">
						<img src="__PUBLIC__/image/admin/icon_edit.gif" border="0" height="16" width="16">
					</a>
					<a href="__URL__/delete_snatch?id={$snatch.act_id}" onclick="" title="移除">
						<img src="__PUBLIC__/image/admin/icon_drop.gif" border="0" height="16" width="16">
					</a>
				</td>
			</tr>
			</volist>
		</table>
	</div>
</form>

<script type="text/javascript" language="JavaScript">

var display_yes 	= 	(Browser.isIE) ? 'block' : 'table-row-group';
document.forms['theForm'].elements['snatch_name'].focus();
/**
* 检查表单输入的数据
*/
function validate(){
	validator = new Validator("theForm");
	validator.required("snatch_name",  no_name);
	validator.required("desc",         no_desc);
	validator.isNullOption("goods_id", no_goods_id);
	validator.isTime("start_time", invalid_starttime, true);
	validator.isTime("end_time", invalid_endtime, true);
	validator.gt("end_time", "start_time", invalid_gt);
	validator.gt("end_price", "start_price", invalid_price);
	validator.isNumber("start_price", invalid_min_price, true);
	validator.isNumber("max_price", invalid_max_price, true);
	validator.isInt("cost_points", invalid_integral, true);

	if (document.forms['theForm'].elements['act'] == "insert"){
		validator.required("password", no_password);
	}
	return validator.passed();
}

function searchGoods(){
	var filter 		= 	new Object;
	filter.keyword 	= 	document.forms['theForm'].elements['keywords'].value;
	$.ajax({
		url: '__URL__/search_goods',
		type: 'get',
		dataType: 'json',
		data: filter,
		beforeSend:function(){
			
		},
		success:function(msg){
			alert(msg);
		}		
	});
}

function searchGoodsResponse(result){
	var frm = document.forms['theForm'];
	var sel = frm.elements['goods_id'];
	var sp = frm.elements['product_id'];

	if (result.error == 0){
	/* 清除 options */
	sel.length = 0;
	sp.length = 0;

	/* 创建 options */
	var goods = result.content.goods;
		if (goods){
			for (i = 0; i < goods.length; i++){
			  var opt = document.createElement("OPTION");
			  opt.value = goods[i].goods_id;
			  opt.text  = goods[i].goods_name;
			  sel.options.add(opt);
			}
		}
		else{
			var opt = document.createElement("OPTION");
			opt.value = 0;
			opt.text  = search_is_null;
			sel.options.add(opt);
		}

		/* 创建 product options */
		var products = result.content.products;
		if (products){
			sp.style.display = display_yes;

			for (i = 0; i < products.length; i++){
				var p_opt = document.createElement("OPTION");
				p_opt.value = products[i].product_id;
				p_opt.text  = products[i].goods_attr_str;
				sp.options.add(p_opt);
			}
		}
		else{
			sp.style.display = 'none';

			var p_opt = document.createElement("OPTION");
			p_opt.value = 0;
			p_opt.text  = search_is_null;
			sp.options.add(p_opt);
		}
	}

	if (result.message.length > 0){
		alert(result.message);
	}
}

function change_good_products(){
	var filter = new Object;
	filter.goods_id = document.forms['theForm'].elements['goods_id'].value;
	Ajax.call('snatch.php?is_ajax=1&act=search_products', filter, searchProductsResponse, 'GET', 'jsON');
}

function searchProductsResponse(result){
	var frm = document.forms['theForm'];
	var sp = frm.elements['product_id'];

	if (result.error == 0){
		/* 清除 options */
		sp.length = 0;

		/* 创建 product options */
		var products = result.content.products;
		if (products.length){
			sp.style.display = display_yes;

			for (i = 0; i < products.length; i++){
				var p_opt = document.createElement("OPTION");
				p_opt.value = products[i].product_id;
				p_opt.text  = products[i].goods_attr_str;
				sp.options.add(p_opt);
			}
		}
		else{
			sp.style.display = 'none';

			var p_opt = document.createElement("OPTION");
			p_opt.value = 0;
			p_opt.text  = search_is_null;
			sp.options.add(p_opt);
		}
	}
	if (result.message.length > 0){
		alert(result.message);
	}
}

</script>


